var url = "sky.php";
$(function() {	
	$.post(url,{doAction:"act_loginFront"},function(data){
		if(data.flag==1){			
			window.location.href = "./middle.html";
		}
	},"json");
	document.onkeydown = function(e) {
		var ev = document.all ? window.event : e;
		if (ev.keyCode == 13) {
			login();
		}
	}

});
var submit = false;//是否已提交（true是；false否）
//登陆，dwr提交
function login() {		
	if (submit) {
		return false;
	}	
	submit = true;	
	var staffCode = encodeURIComponent($.trim($("#name").val()));
	var password =  encodeURIComponent($.trim($("#pwd").val()));
	var validateCode = encodeURIComponent($.trim($("#validateCode").val()));
	if (!checkNull(staffCode, password,validateCode)) {	
		submit = false;
		return;
	}
	$.post(url,{doAction:"act_login",staffCode:staffCode,password:password,validateCode:validateCode},getStaff4loginCallBack,"json");
}
//空串判断
function checkNull(staffCode, password,validateCode) {
	
	if ("" == staffCode) {
		alert("请输入账号！");
		$("#name").focus();		
		return false;
	}	
	if ("" == password) {
		alert("请输入密码！");
		$("#pwd").focus();		
		return false;
	}	
	if ("" == validateCode) {
		alert("请输入验证码！");
		$("#validateCode").focus();		
		return false;
	}	
	return true;
}
//登陆回调
function getStaff4loginCallBack(data) {

	if (data.flag == -100) {
		submit = false;
		alert("验证码错误");
	} else if (data.flag == 0) {
		submit = false;
		alert("账号或密码错误!");		
	} else if (data.flag == 2) {
		submit = false;
		alert("您的帐号目前处于锁定状态，详细请联系您的推荐人。");
	} else {
		//指向首页
		if($('#scrollDiv').eq(0).find("ul:first").find("li:first").html()=='英文'){
			window.location.href = "./english/middle.html";
		}else{
			window.location.href = "./middle.html";
		}
		
	}
	changeImg();
	$("#validateCode").val("")
}

function changeImg(){	
	document.getElementById("validateCodeImg").src="authImage.php?"+Math.random();
}